

//import layoutVariety.Widget
import javax.swing._
import scala.collection.mutable.ListBuffer
import layoutVariety.AlignDirection._
import scala.swing.BoxPanel
import scala.swing.Orientation

package layoutVariety{
		
	/**
	 * The abstract class representing a container.
	 * 
	 * the class extends widget and adds layout functionality
	 *  
	 * 
	 *
	 */
	class Box(ref : Int, name : String = "") extends Widget(ref) {

		// initialize JPanel
		jc = new BoxPanel(Orientation.Horizontal)
		
		// the contained widgets
		protected val children = new ListBuffer[Widget]()
  			
		// - ISSUE - zeros all of the attributes and handlers... 
		// copies elements of one panel to another 
		protected def initNewPanel(newPanel : BoxPanel, oldPanel : BoxPanel)
		{
		  // copy contents
		  for (c <- oldPanel.contents)
			  newPanel.contents += c;
	  
		}
		
		/* public interface */
		def addWidget(child : Widget)  
		{
  			// add the swing element to the panel
			jc.asInstanceOf[BoxPanel].contents += child.getWidget;
			
			// add the widget to the children list
			children+=child;
			
		}
		
		def setAlignment(alignment : AlignDirection) : Box = 
		{
		  var newPanel : BoxPanel = null;
		  
		  if (alignment == Hor)
		  {
		    newPanel = new BoxPanel(Orientation.Horizontal)			
		  }
		  else
		  {
		    newPanel = new BoxPanel(Orientation.Vertical);			
		  }
		  
		  initNewPanel(newPanel,jc.asInstanceOf[BoxPanel]);
		  jc = newPanel
		  
		  return this;
		}
				
	}
}